package com.jiantong.common.util;


import com.jiantong.common.model.BaseUser;

/**
 * Mail: F@terminus.io
 * Data: 16/6/28
 * Author: yangzefeng
 */
public final class UserUtil {

    private static ThreadLocal<BaseUser> user = new ThreadLocal<>();

    public static void putCurrentUser(BaseUser baseUser) {
        user.set(baseUser);
    }

    public static <T extends BaseUser> T getCurrentUser() {
        return (T)user.get();
    }

    public static void clearCurrentUser() {
        user.remove();
    }

    public static Long getUserId() {
        BaseUser baseUser = user.get();
        if (null != baseUser) {
            return baseUser.getId();
        }
        return null;
    }
}
